/*
 * @Author: yanzengyong 709402944@qq.com
 * @Date: 2025-07-21 17:16:55
 * @LastEditors: yanzengyong 709402944@qq.com
 * @LastEditTime: 2025-07-22 18:25:32
 * @FilePath: /cyj-boot-parent/cyj-boot-web/src/components/Common/largeFileUpload/src/typing.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 定义文件分片接口
export interface Chunk {
  index: number;
  chunk: Blob;
  size: number;
  total: number;
  uploaded: boolean;
  retryCount: number;
}

// 定义组件props类型
export interface UploaderProps {
  chunkSize?: number;
  concurrentUploads?: number;
  // headers?: Record<string, string>;
  // params?: Record<string, any>;
  autoStart?: boolean;
  retryCount?: number;
  allowedFileTypes?: string[];
  useLargeSize?: number;
  maxFileSize?: number;
  showProgress?: boolean;
  showSpeed?: boolean;
  showRetry?: boolean;
  successMessage?: string;
  errorMessage?: string;
  timeOut?: number;
}

// 定义组件emits类型
export interface UploaderEmits {
  (event: 'upload-start', fileInfo: FileInfo): void;
  (event: 'upload-progress', progress: number): void;
  (event: 'upload-success', result: UploadResult): void;
  (event: 'upload-error', error: UploadError): void;
  (event: 'chunk-uploaded', chunkInfo: ChunkInfo): void;
  (event: 'chunk-error', error: ChunkError): void;
  (event: 'on-clear'): void;
}

// 定义文件信息类型
export interface FileInfo {
  fileHash: string;
  fileName: string;
  fileSize: number;
  totalChunks: number;
}

// 定义上传结果类型
export interface UploadResult extends FileInfo {
  fileUrl?: string;
  totalTime: number;
  avgSpeed: string;
  bucketName: string;
  fileKey: string;
  appId: string;
}

// 定义上传错误类型
export interface UploadError {
  error: Error;
  chunkIndex?: number;
}

// 定义分片信息类型
export interface ChunkInfo {
  chunkIndex: number;
  totalChunks: number;
  fileHash: string;
}

// 定义分片错误类型
export interface ChunkError extends ChunkInfo {
  error: Error;
}
